home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / C_BAR1.ARJ / PRBAR.C < prev    next >
C/C++ Source or Header  |  1992-02-27  |  2KB  |  68 lines

  1. /*
  2.  * prbar - print a thick or thin line or space
  3.  * IBM Graphics Printer version
  4.  * written 1987 David J. Rodman
  5.  * Paradise Technology, Inc.
  6.  * Compuserve 70007,1545
  7.  * This code is placed into the public domain.  Have at it.
  8.  */
  9.  
  10. #include <stdio.h>
  11. extern int res, depth;     /* settings for width and heigth of barcode */
  12. extern char *text[];       /* text for the right-hand part of label */
  13. extern lineno;        /* current line of label */
  14.  
  15. static char *str;    /* the string to encode */
  16.  
  17. /*
  18.  * initialize the printer as required to print string s
  19.  * the ratio of thick to thin is 3:1, and there will be 3 thicks and 6 thins.
  20.  * each character is terminated by a thin space.
  21.  * thus, each character is 16 * res dots wide (res * 6 + 3*res * 3 + res)
  22.  * each string starts and stops with a special code, so there are
  23.  * strlen(s) + 2 bytes to print.
  24.  */
  25. prinit(s)
  26.     char *s;
  27. {
  28.     unsigned n;
  29.  
  30.     str = s;    
  31.     n = 16 * res * (strlen(s) + 2);        /* total # of graphic bytes */
  32.     printf("%c1", 0x1b);                 /* 10 lpi */
  33.     printf("%cL%c%c", 0x1b, n & 0xff, n >> 8);    /* 120 DPI graphics */
  34. }
  35.  
  36. /*
  37.  * This is the place to put any other printer reset commands you want,
  38.  *    like 6 LPI, condensed print, or whatever.
  39.  */
  40. prfini()
  41. {
  42.     printf("%c3%c\n%s\n", 0x1b, 36, text[0]);
  43. }
  44.  
  45. /*
  46.  * print an individual line or space, thick or thin 
  47.  * args are boolean
  48.  */
  49. prbar(thick, line)
  50. {
  51.     int w, c;
  52.  
  53.     w = res * (thick ? 3 : 1);
  54.     c = line ? 0xff : 0;
  55.     while(w--)
  56.         printf("%c", c);
  57. }
  58.  
  59. /*
  60.  * move down one line, printing the appropriate text
  61.  */
  62. prdown()
  63. {
  64.      printf(" %s", text[lineno++]);
  65.     printf("%c%c", 0x0d, 0x0a);
  66. }
  67.  
  68.